<template>
	<page-meta :root-font-size="fontSize"></page-meta>
	<view class="mycontent">
		<!-- 自定义导航栏 -->
		<!-- <u-navbar :is-back="false" :is-fixed="isFixed">
			<view class="slot-wrap">
				<u-dropdown class="u-dropdown">
					<u-dropdown-item v-model="value1" :title="options[value1].label" :options="options" @change='dropDownChange(options[value1].label)'></u-dropdown-item>
				</u-dropdown>
			</view>
		</u-navbar>
		<view style="position: relative;z-index: 20;">
			<u-tabs :list="titleList" :is-scroll="false" :current="current" @change="tabChange"></u-tabs>
		</view> -->
		<view style="margin-top: 0rpx;width: 100%;">
			<view class="topContent">
				<view class="dropdownBox">
					<u-dropdown ref="uDropdown">
						<u-dropdown-item v-model="value1" :title="options[value1].label" :options="options" @change="dropDownChange"></u-dropdown-item>
					</u-dropdown>
				</view>
			</view>
			<view>
				<u-tabs :list="titleList" :is-scroll="false" :current="current" @change="tabChange"></u-tabs>
			</view>
		</view>
		<scroll-view scroll-y="true" :style="{height: Height}" refresher-enabled="true" :refresher-threshold="100"
		@refresherrefresh="onRefresh" :refresher-triggered="triggered">
			<view class="orderContent">
				<bus-item v-if="showBusOrder" :busOrderList="showOrderArr" :fontSize="fontSize"></bus-item>
				<!-- <scenic-item v-if="showScenicOrder" :scenicList="orderList" @updateOrder= "updateOrder"></scenic-item> -->
				<!-- <hotel-item v-if="showHotelOrder" :hotelOrderList="orderList"></hotel-item> -->
			</view>
			<u-empty :style="{height:Height}" text="无订单信息" v-if="showOrderArr.length == 0"></u-empty>
		</scroll-view>
	</view>
</template>

<script>
	var _self;
	import busItem from './subView/busTicketItem'
	export default {
		components: {
			busItem,
		},
		data() {
			return {
				fontSize:'',
				value1: 0,
				isFixed: true,
				options: [{
					label: '汽车票',
					value: 0,
				}
				,{
					label: '定制班线',
					value: 1,
				},{
					label: '机场专线',
					value: 2,
				},{
					label: '乡镇客运',
					value: 3,
				},{
					label: '校园直通车',
					value: 4,
				}
				],
				titleList:[
					{
						name:'进行中'
					},
					{
						name:'已完成'
					},
					{
						name:'已取消'
					},
					{
						name:'全部'
					}
				],
				current:0,
				Height:'',
				triggered:false,
				showBusOrder:true,
				orderList:[],
				userInfo:[],
				showOrderArr:[]
			}
		},
		onLoad() {
			_self = this;
			_self.fontSize = getApp().globalData.fontSize;
			
			//获取系统信息
			uni.getSystemInfo({
				success: function(res) {
					console.log(res)
					// #ifdef H5
					_self.Height = res.windowHeight - '80' + 'px';
					// #endif
					
					// #ifndef H5
					_self.Height = res.windowHeight - '120' + 'px';
					// #endif
				}
			});
		},
		onShow() {
			// #ifdef APP
			_self.judgeUserInfo();
			// #endif
			uni.getStorage({
				key: 'userInfo',
				success: function(res) {
					console.log('用户信息',res.data);
					_self.userInfo = res.data;
					_self.GetBookLogByID();
				},fail:function(){
					// #ifdef MP-WEIXIN
					uni.$emit('getAuthorize', {
					    data: '授权'
					});
					// #endif
				}
			})
		},
		onPullDownRefresh() {
			_self.GetBookLogByID();
		},
		methods: {
			//-----------------------------------------------自定义刷新-----------------------------------------------
			onRefresh(){
				_self.triggered = true;
			},
			//-------------------------------------------判断用户是否登陆-------------------------------------------
			judgeUserInfo: function() {
				uni.getStorage({
					key: 'userInfo',
					success: function(res) {
						// console.log('用户信息',res.data);
						_self.userInfo = res.data;
						_self.GetBookLogByID();
					},fail:function(){
						uni.navigateTo({
							url: '../Login/Login'
						});
					}
				})
			},
			//----------------------------------------点击下拉菜单----------------------------------------
			dropDownChange:function(res){
				console.log('选择了',res);
				console.log('选择了',_self.options[res].label);
				
				// if(res == '汽车票'){
				// 	console.log('选择了汽车票');
				// }else {
				// }
			},
			//----------------------------------------点击菜单----------------------------------------
			tabChange:function(index){ 
				_self.current = index;
				switch (index) {
					case 0:
					// 进行中4 7 22 34
						_self.showOrderArr = _self.orderList.filter(item => {
							return item.State == 4 || item.State == 7 || item.State == 22 || item.State == 34;
						})
						break;
					case 1:
					//已完成3 5 6
						_self.showOrderArr = _self.orderList.filter(item => {
							return item.State == 3 || item.State == 5 || item.State == 6;
						})
						break;
					case 2:
					//已取消 9
						_self.showOrderArr = _self.orderList.filter(item => {
							return item.State == 9;
						})
						break;
					case 3:
					//全部
						_self.GetBookLogByID();
						break;
					
				}
			},
			//---------------------------------------------快捷弹窗---------------------------------------------
			showToast: function(title, type) {
				this.$refs.uToast.show({
					title: title,
					type: type
				})
			},
			//--------------------时间格式化------------------------------
			formatTime: function(time) {
				var dateTime = time.replace('T', ' ');
				if (dateTime.indexOf('1900') > -1) {
					return '';
				} else {
					return dateTime;
				}
				// if(time==null){
				// 	return time;
				// }else{
				// 	var dateTime = time.substring(0, 16);
				// 	return dateTime;
				// }
			},
			//----------------------------------------获取订单----------------------------------------
			GetBookLogByID() {
				_self = this;
				_self.orderList = [];
				console.log('用户信息',_self.userInfo);
				uni.showLoading({
					title:'正在加载订单...'
				}) 
				uni.request({
					url: _self.$h.expressInterface.expressInterface.GetBookLogByID.url,
					method: _self.$h.expressInterface.expressInterface.GetBookLogByID.method,
					data: {
						ClientID:_self.userInfo.Id,
						appSystemCode:_self.$h.expressInterface.expressInterface.appSystemCode.appSystemCode
					},
					success(res) {
						// console.log('订单信息',res); 
						if (res.data.Success) {
							_self.orderList = JSON.parse(res.data.Data);
							console.log(_self.orderList);  
							_self.showOrderArr = JSON.parse(res.data.Data);
							if(_self.current == 0){
								_self.showOrderArr = _self.orderList.filter(item => {
									return item.State == 4 || item.State == 7||item.State == 22;
								})
							}else if(_self.current == 1){
								_self.showOrderArr = _self.orderList.filter(item => {
									return item.State == 3 || item.State == 5 || item.State == 6;
								})
							}else if(_self.current == 2){
								_self.showOrderArr = _self.orderList.filter(item => {
									return item.State == 9;
								})
							}
						}else {
							_self.showToast('获取失败','error');
						}
					},
					fail() {
						console.log('失败返回', res);
						_self.$u.toast('网络错误');
					},complete() {
						uni.hideLoading();
						uni.stopPullDownRefresh();
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.mycontent{
		width: 100%;
		height: 100%;
		background-color: #F5F5F5;
	}
	.slot-wrap {
		display: flex;
		align-items: center;
		flex: 1;
		height: 44rpx;
	}
	.topContent{
		/* #ifdef H5 */
		height: 80rpx;
		/* #endif */
		
		/* #ifndef H5 */
		height: 160rpx;
		padding-top: 70rpx;
		/* #endif */
		background-color: #FFFFFF;
		border-bottom: 1upx solid #dadada;
	}
	.orderContent{
		position: relative;
	}
	// 下拉菜单
	.dropdownBox{
		width: 100%;
	}
</style>
